home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / pd0836.zip / CVF.H < prev    next >
C/C++ Source or Header  |  1993-04-30  |  9KB  |  216 lines

  1. /***    CVF.H - Definitions for the DoubleSpace Compressed Volume File
  2.  *
  3.  *      Version 1.00.58  12-Mar-1993
  4.  */
  5.  
  6. #pragma pack(1)
  7.  
  8. #ifndef BYTE
  9. typedef unsigned char  BYTE;    // 1 byte
  10. #endif
  11.  
  12. #ifndef WORD
  13. typedef unsigned short WORD;    // 2 bytes
  14. #endif
  15.  
  16. #ifndef DWORD
  17. typedef unsigned long  DWORD;   // 4 bytes
  18. #endif
  19.  
  20.  
  21. /***    szDS_STAMP1, szDS_STAMP2 - Stamps that identify a DoubleSpace CVF
  22.  *
  23.  *      These two stamps are written, respectively, at the following
  24.  *      two locations in the CVF:
  25.  *        1) csecMDReserved*cbPerSec+512
  26.  *        2) Start of last sector of CVF
  27.  *
  28.  *      The first stamp starts with F8, to be compatible with Colorado
  29.  *      Memory Systems tape backup software.
  30.  *
  31.  */
  32. #define szDS_STAMP1  "\xf8" "DR" // First CVF stamp
  33. #define szDS_STAMP2  "MDR"      // Second CVF stamp
  34. #define cbDS_STAMP   4          // Length of stamp (includes NULL)
  35.  
  36.  
  37. /***    csecRESERVED1 - count of sectors in CVF region RESERVED1
  38.  *
  39.  *      This is the region between the BitFAT and the MDFAT.
  40.  */
  41. #define csecRESERVED1  1        // Hard-coded size of reserved region 1
  42.  
  43.  
  44. /***    csecRESERVED2 - count of sectors in CVF region RESERVED2
  45.  *
  46.  *      This is the region between the MDFAT and the DOS BOOT region.
  47.  */
  48. #define csecRESERVED2 31        // Hard-coded size of reserved region 2
  49.  
  50.  
  51. /***    csecRESERVED4 - count of sectors in CVF region RESERVED4
  52.  *
  53.  *      This is the region between the ROOTDIR and the SECTORHEAP.
  54.  */
  55. #define csecRESERVED4  2        // Hard-coded size of reserved region 4
  56.  
  57.  
  58. /***    csecRETRACT_STAMP - count of sectors at end of Sector Heap
  59.  *
  60.  *      The tail CVF stamp is stored in the last *complete* sector
  61.  *      of the CVF.  That is, if the CVF is exactly a multiple of 512
  62.  *      bytes in length, then the last sector contains the stamp.
  63.  *      If the CVF is *not* a multiple of 512 bytes, then the stamp
  64.  *      is stored in the next to last sector in the file, which is
  65.  *      512 bytes long (the last sector is less than 512 bytes).
  66.  */
  67. #define csecRETRACT_STAMP   1
  68.  
  69.  
  70. /***    cbPER_BITFAT_PAGE - size of a BitFAT page in DBLSPACE.BIN
  71.  *
  72.  *      DBLSPACE.BIN "pages" the BitFAT into a buffer of this size,
  73.  *      so the BitFAT total size must be a multiple of this page size.
  74.  */
  75. #define cbPER_BITFAT_PAGE   2048
  76.  
  77.  
  78. /***    MDBPB - Compressed Volume File "BIOS Parameter Block"
  79.  *
  80.  *      This structure appears in the first sector of a Compressed
  81.  *      Volume File, and contains information that describes the
  82.  *      size and location of the remaining parts of the CVF.
  83.  */
  84.  
  85. typedef struct { /* mp */
  86.  
  87.     BYTE    jmpBOOT[3];     // Jump to bootstrap routine
  88.     char    achOEMName[8];  // OEM Name ("MSDSP6.0")
  89.  
  90.     /*
  91.      *  The following fields are a clone of the MS-DOS BPB
  92.      */
  93.     WORD    cbPerSec;       // Count of bytes per sector (always 512)
  94.     BYTE    csecPerClu;     // Count of sectors per cluster (always 16)
  95.     WORD    csecReserved;   // Count of reserved sectors.
  96.     BYTE    cFATs;          // Count of FATs (always 1)
  97.                             // NOTE: Even though we store 1 on the disk,
  98.                             //       when the drive is mounted, DBLSPACE.BIN
  99.                             //       simulates 2 FATs.
  100.     WORD    cRootDirEntries;// Count of root directory entries (always 512)
  101.     WORD    csecTotalWORD;  // Count of total sectors (see csecTotalDWORD if 0)
  102.     BYTE    bMedia;         // Media byte (always 0xF8 == hard disk)
  103.     WORD    csecFAT;        // Count of sectors occupied by the FAT
  104.     WORD    csecPerTrack;   // Count of sectors per track (random, ignored)
  105.     WORD    cHeads;         // Count of heads (random, ignored)
  106.     DWORD   csecHidden;     // Count of hidden sectors
  107.     DWORD   csecTotalDWORD; // Count of total sectors
  108.  
  109.     /*
  110.      *  The following fields are DoubleSpace extensions
  111.      */
  112.  
  113.     WORD    secMDFATStart;  // Logical sector of start of MDFAT
  114.     BYTE    nLog2cbPerSec;  // Log base 2 of cbPerSec
  115.     WORD    csecMDReserved; // Number of sectors before DOS BOOT sector
  116.     WORD    secRootDirStart;// Logical sector of start of root directory
  117.     WORD    secHeapStart;   // Logical sector of start of sector heap
  118.     WORD    cluFirstData;   // Number of MDFAT entries (clusters) which are
  119.                             // occupied by the DOS boot sector, reserved area,
  120.                             // and root directory.
  121.     BYTE    cpageBitFAT;    // Count of 2K pages in the BitFAT
  122.     WORD    RESERVED1;
  123.     BYTE    nLog2csecPerClu;// Log base 2 of csecPerClu
  124.     WORD    RESERVED2;
  125.     DWORD   RESERVED3;
  126.     DWORD   RESERVED4;
  127.     BYTE    f12BitFAT;      // 1 => 12-bit FAT, 0 => 16-bit FAT
  128.     WORD    cmbCVFMax;      // Maximum CVF capacity, in megabytes (1024*1024)
  129.                             //   This is the maximum amount of *uncompressed*
  130.                             //   data that can be stored on the disk, and is
  131.                             //   used to set the space reserved for the BitFAT,
  132.                             //   MDFAT, and FAT.  This is also the upper limit
  133.                             //   on the size of the Sector Heap, in the case
  134.                             //   where all the data stored in the CVF is
  135.                             //   incompressible (1.0 to 1.0).
  136. } MDBPB;
  137. typedef MDBPB *PMDBPB;  /* pmp */
  138.  
  139.  
  140. /***    MDFATENTRY - Entry in the MDFAT
  141.  *
  142.  *      The MDFAT is a table that is used to keep track of the data for
  143.  *      each cluster in the DoubleSpace drive.
  144.  *
  145.  *      The MDFAT parallels the DOS FAT in the CVF.
  146.  *
  147.  *      In a normal FAT partition, the starting sector for a cluster is found
  148.  *      by this formula:
  149.  *
  150.  *          sector  = FAT overhead + cluster number * sectors per cluster
  151.  *
  152.  *      This formula is simple, and allows the FAT to be used both as a
  153.  *      free space map and also as a means of linking the clusters of a
  154.  *      file together.  However, it also means that the physical space
  155.  *      occupied by a file is a multiple of the cluster size.
  156.  *
  157.  *      In a CVF, on the other hand, this mapping does not apply.  The DOS
  158.  *      FAT is still used by MS-DOS for "virtual" space allocation and linking
  159.  *      file clusters, but no physical space allocation in the CVF occurs
  160.  *      until disk I/O occurs on the data of a cluster.
  161.  *
  162.  *      To find the data for a cluster in a CVF, the cluster number is used
  163.  *      as an index into the MDFAT, and the MDFAT Entry describes the state,
  164.  *      location, and size of the cluster, as follows:
  165.  *
  166.  *      secStart
  167.  *          This is the logical sector in the CVF Sector Heap where the
  168.  *          data for the cluster resides.  All the sectors of this cluster
  169.  *          are stored contiguously, starting at this location.
  170.  *          Add 1 to this value to get the logical sector number (from the
  171.  *          beginning of the CVF), i.e., if secStart is 134, then the sector
  172.  *          is located at sector 135 in the CVF.
  173.  *
  174.  *      csecCoded
  175.  *          This is the length of the cluster data, in sectors.
  176.  *          Values 0..15 are interpreted as 1..16.
  177.  *          A maximally compressed cluster will have length 0 (1 sector).
  178.  *          An uncompressed cluster will have length 15 (16 sectors).
  179.  *
  180.  *      csecPlain
  181.  *          This is the length of the uncompressed cluster data, in sectors.
  182.  *          Values are 0..15, as with csecCoded.  This value is usually
  183.  *          MDBPB.csecPerClu-1 (15), except for the last cluster of a file,
  184.  *          which may be shorter, since the cluster has not been completely
  185.  *          written.
  186.  *
  187.  *          NOTE: For a cluster that is uncompressed (fUncoded == 1), this
  188.  *                field is undefined.
  189.  *
  190.  *      fUncoded
  191.  *          Indicates whether the cluster data is compressed.
  192.  *          1 => uncompressed; 0 => compressed.  If DoubleSpace is unable
  193.  *          to achieve at least a 1 sector saving, data is stored uncompressed.
  194.  *
  195.  *      fUsed
  196.  *          Indicates whether this entry is in use.  This is used to allow
  197.  *          DoubleSpace to support FAT "undelete" programs.  DBLSPACE.BIN scans
  198.  *          a FAT sector when it is written to disk to infer three types
  199.  *          of operations:
  200.  *
  201.  *          1) Cluster allocation by DOS
  202.  *          2) Cluster free (by DOS or a utility program, like a defragger)
  203.  *          3) Cluster "resurrection" by an undelete program.
  204.  */
  205. typedef struct { /* mfe */
  206.     unsigned long secStart       : 21; // Starting sector in sector heap
  207.     unsigned int  fRESERVED      :  1; // Reserved for future use
  208.     unsigned int  csecCoded     :  4; // Length of coded data (in sectors)
  209.     unsigned int  csecPlain     :  4; // Length of original data (in sectors)
  210.     unsigned int  fUncoded     :  1; // TRUE => coded data is NOT CODED
  211.     unsigned int  fUsed      :  1; // TRUE => MDFAT entry is allocate
  212. } MDFATENTRY;
  213. typedef MDFATENTRY *PMDFATENTRY; /* pmfe */
  214.  
  215. #define cbMDFATENTRY   4    // Size of an MDFATENTRY in bytes
  216.